package org.aj.common.web.file.bean;

import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

/**
 * @autor aj {"base64File":"base64文件","type":"约定好的文件相对路径","fileName":"文件名"}
 * description 用于封装前端调用文件上传接口传递的参数
 * date  2021/10/1 10:08
 */
public class FileVo {
    /**
     * 文件对应的base64字符串
     */
    @NotBlank(message = "请上传文件")
    String base64File;
    /**
     * 子文件夹的路径 由后端人员告知调用者
     * 例如：yidao-judicial/notary/piv
     */
    @NotBlank(message = "无type标识")
    String type;
    /**
     * 文件名称
     */
    @Size(min = 1,max = 64)
    @NotBlank(message = "请传入文件名称")
    String fileName;

    /**
     * 是否需要保留原文件的名称
     */
    Boolean needKeepOriginalName;

    /**
     * 上一次获得文件获得的相对路径
     * 若有则会覆盖掉之前上传的文件
     */
    String beforeRelativePath;



    public String getBase64File() {
        return base64File;
    }

    public FileVo setBase64File(String base64File) {
        this.base64File = base64File;
        return this;
    }

    public String getType() {
        return type;
    }

    public FileVo setType(String type) {
        this.type = type;
        return this;
    }

    public String getFileName() {
        return fileName;
    }

    public FileVo setFileName(String fileName) {
        this.fileName = fileName;
        return this;
    }

    public Boolean getNeedKeepOriginalName() {
        return needKeepOriginalName;
    }

    public FileVo setNeedKeepOriginalName(Boolean needKeepOriginalName) {
        this.needKeepOriginalName = needKeepOriginalName;
        return this;
    }

    public String getBeforeRelativePath() {
        return beforeRelativePath;
    }

    public FileVo setBeforeRelativePath(String beforeRelativePath) {
        this.beforeRelativePath = beforeRelativePath;
        return this;
    }

    @Override
    public String toString() {
        return "FileVo{" +
                "base64File='" + base64File + '\'' +
                ", type='" + type + '\'' +
                ", fileName='" + fileName + '\'' +
                ", needKeepOriginalName=" + needKeepOriginalName +
                ", beforeRelativePath='" + beforeRelativePath + '\'' +
                '}';
    }


    public String printButOnlyBase64Length() {

        int base64Length = StringUtils.isBlank(base64File) ? 0 :base64File.length();

        return "FileVo{" +
                "base64FileLength='" + base64Length + '\'' +
                ", type='" + type + '\'' +
                ", fileName='" + fileName + '\'' +
                ", needKeepOriginalName=" + needKeepOriginalName +
                ", beforeRelativePath='" + beforeRelativePath + '\'' +
                '}';
    }
}
